package com.oig.sys.msg.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oig.common.exception.BadRequestException;
import com.oig.common.module.SysRequest;
import com.oig.sys.msg.dto.TaskDto;
import com.oig.sys.msg.mapper.TbTaskMapper;
import com.oig.sys.msg.vo.TaskVo;
import com.oig.sys.security.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "用户的任务查询")
@RestController
@RequestMapping(value = "/userTask")
@Slf4j
@RequiredArgsConstructor
public class UserTaskController {

    private final TbTaskMapper taskMapper;


    /**
     * 普通查询
     */
    @Operation(summary = "用户查询自己处理的任务,公共功能，不设权限登，录即可")
    @PostMapping("/page")
    public PageInfo<TaskVo> queryMyDealAsPage(@RequestBody SysRequest<TaskDto> sysRequest){
        log.info("user deal task query 2:{}", sysRequest);
        if (sysRequest.getParamDto()==null){
            throw new BadRequestException("查询条件不能为空");
        }
        sysRequest.getParamDto().setDealId(SecurityUtil.getDefineUserMain().getId());
        //sysRequest.getParamDto().setOrgzId(SecurityUtil.getDefineUserMain().getOrgzId());
        PageHelper.startPage(sysRequest.getPageNo(), sysRequest.getPageSize());
        List<TaskVo> list = this.taskMapper.queryTask(sysRequest.getParamDto());
        return new PageInfo<>(list);
    }


    /**
     * 普通查询
     */
    @Operation(summary = "用户查询自己的分配任务,公共功能，不设权限登，录即可")
    @PostMapping("/pageMe")
    public PageInfo<TaskVo> queryMyWatchAsPage(@RequestBody SysRequest<TaskDto> sysRequest){
        log.info("user watch task query 2:{}", sysRequest);
        TaskDto taskDto = sysRequest.getParamDto();
        if (taskDto==null){
            taskDto = new TaskDto();
        }
        //taskDto.setOrgzId(SecurityUtil.getDefineUserMain().getOrgzId());
        taskDto.setWatchId(SecurityUtil.getDefineUserMain().getId());
        sysRequest.setParamDto(taskDto) ;
        PageHelper.startPage(sysRequest.getPageNo(), sysRequest.getPageSize());
        List<TaskVo> list = this.taskMapper.queryTask(sysRequest.getParamDto());
        return new PageInfo<>(list);
    }

}
